package com.meilingcloud.web.controller.system;

import com.meilingcloud.common.core.domain.AjaxResult;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
public class WebSocketController {

    private final SimpMessagingTemplate simpMessagingTemplate;

    @GetMapping("/testWebSocket/{msg}")
    public AjaxResult testWebSocket(@PathVariable("msg") String msg) {
        simpMessagingTemplate.convertAndSend("/topic/test", "hello" + msg);
        return AjaxResult.success();
    }

}
